package com.xiaoye.app.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaoye.app.common.MsgReturn;
import com.xiaoye.app.entity.Page;
import com.xiaoye.app.entity.User;
import com.xiaoye.app.mapper.UserMapper;
import com.xiaoye.app.service.UserService;
import com.xiaoye.app.util.PropertyCodeMsgUtil;

@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;

	@Override
	public MsgReturn selectUserList(User user) throws SQLException {
		List<User> userList = userMapper.selectUserList(user);
		if (userList == null || userList.size() <= 0) {
			return MsgReturn.NODATA();
		}
		int totalCount = userMapper.selectUserListCount(user);
		if (totalCount <= 0) {
			return MsgReturn.NODATA();
		}
		return new MsgReturn(MsgReturn.SUCCESS, PropertyCodeMsgUtil.getPropertyValue(MsgReturn.SUCCESS), userList,
				totalCount);
	}

	@Override
	public MsgReturn selectUserListCount(User user) throws SQLException {
		int count = userMapper.selectUserListCount(user);
		if (count <= 0) {
			return MsgReturn.NODATA();
		}
		return MsgReturn.success(count);
	}

	@Override
	public MsgReturn login(User user) throws SQLException {
		User returnUser = userMapper.login(user);
		if (returnUser == null) {
			return MsgReturn.NODATA();
		}
		return MsgReturn.success(returnUser);
	}

}
